import { useRoute } from 'vue-router'

import { roleApi } from '@/apis'
import { TableRefHook, useDialog } from '@/hooks'

type Params = {
  tableRefHook: TableRefHook
}

export function useOperation({ tableRefHook }: Params) {
  const { showConfirm } = useDialog()
  const route = useRoute()

  function handleCancelAuth(id: string) {
    showConfirm({
      content: '确认取消授权？',
      onOk: async () => {
        await roleApi.cancelAuthUser(route.params.id as string, {
          ids: [id]
        })

        tableRefHook.refresh()
      }
    })
  }

  return {
    handleCancelAuth
  }
}
